use fltk::{prelude::*, *,enums::*,tree::*};
use fltk_theme::*;
use thread;

/**
 * 主函数
 */
fn main() {
    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let theme = WidgetTheme::new(ThemeType::Metro);
    theme.apply();
    let mut win = window::Window::new(0, 0, 800, 600, "window");
    app::background(255, 255, 255);
    let mut menu = menu::Choice::new(50, 50, 100, 30, "");
    
    for i in 1..10 {
        let ss = &"菜单";
        let  s = format!("{}{}", ss, i.to_string());
        menu.add_choice(&s);
    }
    menu.set_callback(|c| {
        println!("{:?}", c.choice().unwrap());
    });
    let mut menu_bar = menu::MenuBar::new(0, 0, 800, 30, "主菜单");
    menu_bar.set_frame(FrameType::FlatBox);
    menu_bar.add(
        "文件/新建\t",
        enums::Shortcut::Ctrl | 'n',
        menu::MenuFlag::Normal,
        cb,
    );
    /**
     * 树
     */
    let mut tree2 = tree::Tree::new(205, 10, 190, 240, "");
    tree2.set_select_mode(TreeSelect::Multi);
    tree2.add("First");
    tree2.add("First/1st");
    win.make_resizable(true);
    win.end();
    win.show();
    app.run().unwrap();
}

/**
 * 菜单选择项捕获
 */
fn cb(ex: &mut impl MenuExt) {
    if let Some(choice) = ex.choice() {
        let str = choice.as_str();
        if str == "新建\t" {
            let mut win2 = window::Window::new(0, 0, 800, 600, "second window");
            win2.clone().center_screen();
            win2.make_resizable(true);
            win2.end();
            win2.show();
        }
        println!("{}", choice.as_str());
    }
}
